package com.xindaoapp.happypet.activity;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xindaoapp.happypet.MainActivity;
import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.api.AddClient;
import com.xindaoapp.happypet.api.Address;
import com.xindaoapp.happypet.application.HappyPetApplication;
import com.xindaoapp.happypet.bean.BaseEntity;
import com.xindaoapp.happypet.bean.UpdateInfo;
import com.xindaoapp.happypet.utils.CommonParameter.UserState;
import com.xindaoapp.happypet.utils.CommonUtil;
import com.xindaoapp.happypet.utils.Constants;
import com.xindaoapp.happypet.utils.Constants.LOGINMODE;
import com.xindaoapp.happypet.utils.DataCleanManager;
import com.xindaoapp.happypet.utils.IRequest;
import com.xindaoapp.happypet.utils.LoginManager;
import com.xindaoapp.happypet.utils.ProgressHUD;
import com.xindaoapp.happypet.utils.SharePrefUtil;
import com.xindaoapp.share.SharePopupWindow;

public class SettingActivity extends UMBaseActivity implements OnClickListener {
    protected static final int LOGIN_OK = 0;
    protected static final int LOGIN_TRUE = 20;
    @ViewInject(R.id.tittle_common_cancel2)
    private ImageView tittle_common_cancel2;
    @ViewInject(R.id.tittle_setting_content)
    private TextView tittle_setting_content;
    @ViewInject(R.id.setting_dafen)
    private RelativeLayout setting_dafen;
    @ViewInject(R.id.setting_qingli)
    private RelativeLayout setting_qingli;
    @ViewInject(R.id.setting_huancun)
    private TextView setting_huancun;
    @ViewInject(R.id.setting_message)
    private RelativeLayout setting_message;
    @ViewInject(R.id.setting_exit)
    private RelativeLayout setting_exit;
    @ViewInject(R.id.setting_net)
    private CheckBox setting_net;

    @ViewInject(R.id.setting_sina)
    private RelativeLayout setting_sina;
    @ViewInject(R.id.setting_qq)
    private RelativeLayout setting_qq;
    @ViewInject(R.id.setting_weixin)
    private RelativeLayout setting_weixin;
    @ViewInject(R.id.setting_about)
    private RelativeLayout setting_about;
    @ViewInject(R.id.setting_help)
    private RelativeLayout setting_help;
    @ViewInject(R.id.setting_invite)
    private RelativeLayout setting_invite;



    @ViewInject(R.id.iv_sina_bind)
    private ImageView iv_sina_bind;
    @ViewInject(R.id.iv_weixin_bind)
    private ImageView iv_weixin_bind;
    @ViewInject(R.id.iv_qq_bind)
    private ImageView iv_qq_bind;
    @ViewInject(R.id.tv_sina_bind)
    private TextView tv_sina_bind;
    @ViewInject(R.id.tv_weixin_bind)
    private TextView tv_weixin_bind;
    @ViewInject(R.id.tv_qq_bind)
    private TextView tv_qq_bind;
    @ViewInject(R.id.iv_tishinew)
    private ImageView iv_tishinew;
    @ViewInject(R.id.tv_sina_icon)
    private ImageView tv_sina_icon;
    @ViewInject(R.id.tv_weixin_icon)
    private ImageView tv_weixin_icon;
    @ViewInject(R.id.tv_qq_icon)
    private ImageView tv_qq_icon;

    private boolean loginBySina;
    private boolean loginByQQ;
    private boolean loginByWeiXin;

    private SharePopupWindow win;

    private LoginManager mLoginManager;
    private LoginSuccessReceiver mLoginSuccessReceiver;
    private final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case LOGIN_OK:
                    finish();
                    break;
                case LOGIN_TRUE:
                    Intent intent = new Intent(SettingActivity.this, MainActivity.class);
                    startActivity(intent);
                    break;
                default:
                    break;
            }
        };
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ViewUtils.inject(this);
        mLoginManager = new LoginManager(this, true, new IRequest<LOGINMODE>() {

            @Override
            public void request(LOGINMODE mode) {
                if (mode == LOGINMODE.QQ) {
                    loginByQQ = true;
                } else if (mode == LOGINMODE.SINA) {
                    loginBySina = true;
                } else if (mode == LOGINMODE.WeiXin) {
                    loginByWeiXin = true;
                }
                resetButtonState();
            }
        });
        initClick();
        initView();
        mLoginSuccessReceiver = new LoginSuccessReceiver();
        registerReceiver(mLoginSuccessReceiver, new IntentFilter(
                Constants.ACTION_LOGIN_STATE_CHANGED));
        initWeiboBindStatus();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mLoginSuccessReceiver);
    }


    private void initWeiboBindStatus() {
        HappyPetApplication.get().getMoccaApi().getLoginBinStatus(new IRequest<String>() {

            @Override
            public void request(String content) {
                if (!TextUtils.isEmpty(content)) {
                    // String result = "";
                    if (1 == JSON.parseObject(content).getInteger("wb")) {
                        // result = "wb";
                        loginBySina = true;
                    } else if (1 == JSON.parseObject(content).getInteger("qq")) {
                        // result = "qq";
                        loginByQQ = true;
                    } else if (1 == JSON.parseObject(content).getInteger("wx")) {
                        // result = "wx";
                        loginByWeiXin = true;
                    }
                    // if (t.first == 1) {
                    // loginBySina = true;
                    // }
                    // if (t.second == 1) {
                    // loginByQQ = true;
                    // }
                    resetButtonState();
                }
            }
        });
    }

    private void resetButtonState() {
        if (UserState.isLogged()) {
            if (loginByQQ) {
                iv_qq_bind.setImageResource(R.drawable.s_unbind);
                tv_qq_bind.setText("解绑");
                tv_qq_icon.setImageResource(R.drawable.qqicon);
            }
            if (loginBySina) {
                iv_sina_bind.setImageResource(R.drawable.s_unbind);
                tv_sina_bind.setText("解绑");
                tv_sina_icon.setImageResource(R.drawable.sinaicon);
            }
            if (loginByWeiXin) {
                iv_weixin_bind.setImageResource(R.drawable.s_unbind);
                tv_weixin_bind.setText("解绑");
                tv_weixin_icon.setImageResource(R.drawable.weixinicon_set_gray);
            }
        }

        boolean updatenew = SharePrefUtil.getBoolean(getBaseContext(), "updatenew", false);
        if (updatenew) {
            iv_tishinew.setVisibility(View.VISIBLE);
        } else {
            iv_tishinew.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void onResume() {
        resetButtonState();
        super.onResume();
    }

    private void initView() {
        ((TextView) findViewById(R.id.setting_versionname))
                .setText(CommonUtil.getVersionName(this));
        long size = 0;
        try {
            size =
                    DataCleanManager.getFolderSize(new File(Environment
                            .getExternalStorageDirectory().getAbsolutePath()
                            + "/Android/data/com.xindaoapp.happypet/"));
            size += DataCleanManager.getFolderSize(new File("/sdcard/happypet/"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (size == 0) {
            setting_huancun.setText("0KB");
        } else {
            setting_huancun.setText(String.format("%.2f", size * 1.0 / (1024 * 1024)) + "M");
        }
    }

    private void initClick() {
        tittle_common_cancel2.setOnClickListener(this);
        tittle_setting_content.setText("设置");
        setting_dafen.setOnClickListener(this);
        setting_qingli.setOnClickListener(this);
        findViewById(R.id.setting_version).setOnClickListener(this);
        setting_sina.setOnClickListener(this);
        setting_qq.setOnClickListener(this);
        setting_weixin.setOnClickListener(this);
        setting_about.setOnClickListener(this);
        setting_invite.setOnClickListener(this);
        setting_net.setOnClickListener(this);
        setting_help.setOnClickListener(this);
        tv_sina_bind.setOnClickListener(this);
        tv_qq_bind.setOnClickListener(this);
        setting_message.setOnClickListener(this);
        setting_exit.setOnClickListener(this);
        setting_net.setChecked(false);
        setting_net.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                setting_net.setChecked(false);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.setting_dafen:
                try {
                    Uri uri = Uri.parse("market://details?id=" + getPackageName());
                    Intent dafen = new Intent(Intent.ACTION_VIEW);
                    dafen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    dafen.setData(uri);
                    startActivity(dafen);
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "您手机上没有安装应用市场", Toast.LENGTH_SHORT)
                            .show();
                }
                break;
            case R.id.setting_qingli:
                new AlertDialog.Builder(SettingActivity.this).setMessage("确认清除缓存?")
                        .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                try {
                                    DataCleanManager.deleteFolderFile(Environment
                                            .getExternalStorageDirectory().getAbsolutePath()
                                            + "/Android/data/com.xindaoapp.happypet/", true);
                                    DataCleanManager.deleteFolderFile(Environment
                                            .getExternalStorageDirectory().getAbsolutePath()
                                            + "/happypet/", true);
                                    ImageLoader.getInstance().clearMemoryCache();
                                    ImageLoader.getInstance().clearDiscCache();
                                    initView();
                                } catch (Exception e) {
                                    // TODO: handle exception
                                }
                                // if (null == clearTask) {
                                // clearTask = new ClearTask();
                                // clearTask.execute("");
                                // }
                                dialog.dismiss();
                            }
                        }).setPositiveButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {}
                        }).create().show();
                break;
            case R.id.setting_version:
                checkUpdate();
                break;
            case R.id.tittle_common_cancel2:
                finish();
                break;
            case R.id.setting_invite:
                if (UserState.isLogged(SettingActivity.this)) {
                    startActivity(new Intent(SettingActivity.this, InviteActivity.class));
                }
                break;
            case R.id.setting_sina:
                if (loginBySina) {
                    new AlertDialog.Builder(SettingActivity.this).setMessage("确认解除微博绑定?")
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    deleteSinaBind();
                                    dialog.dismiss();
                                }
                            }).setPositiveButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {}
                            }).create().show();
                } else {
                    mLoginManager.loginSina(false);
                }
                break;
            case R.id.setting_qq:
                if (loginByQQ) {
                    new AlertDialog.Builder(SettingActivity.this).setMessage("确认解除QQ绑定?")
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    deleteQQBind();
                                    dialog.dismiss();
                                }
                            }).setPositiveButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {}
                            }).create().show();
                } else {
                    mLoginManager.loginQQ(false);
                }
                break;

            case R.id.setting_weixin:
                if (loginByWeiXin) {
                    new AlertDialog.Builder(SettingActivity.this).setMessage("确认解除微信绑定?")
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    deleteWeiXinBind();
                                    dialog.dismiss();
                                }
                            }).setPositiveButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {}
                            }).create().show();
                } else {
                    mLoginManager.loginWeixin(false);
                }
                break;
            case R.id.setting_about:
                Intent about = new Intent(this, AboutActivity.class);
                startActivity(about);
                break;
            case R.id.setting_help:
                Intent intent = new Intent(this, MyClubActivity.class);
                intent.putExtra("name", "意见反馈"); // 因长度-3所以加了一个“填充符”
                intent.putExtra("fId", "31"); // 意见反馈版块FID为31
                startActivity(intent);
                break;
            case R.id.setting_message:
                if (UserState.isLogged(SettingActivity.this)) {
                    Intent intent_message = new Intent(this, PushMessageActivity.class);
                    startActivity(intent_message);
                }
                break;
            case R.id.setting_exit:
                if (UserState.isLogged(SettingActivity.this)) {
                    new LoginManager(this).logout();
                    finish();
                }
                break;
            case R.id.tv_sina_bind:
                break;
            case R.id.tv_qq_bind:
                break;
            default:
                break;
        }
    }

    private void deleteSinaBind() {
        final ProgressHUD ProgressDialog = ProgressHUD.show(this, "正在加载...", true, true, null);
        AddClient.get(Address.UNBINDSINA, null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                try {
                    if (null != ProgressDialog && ProgressDialog.isShowing()) {
                        ProgressDialog.dismiss();
                    }
                    BaseEntity parse = JSON.parseObject(content, BaseEntity.class);
                    if (parse.getResult().equals("0")) {
                        loginBySina = false;
                        iv_sina_bind.setImageResource(R.drawable.s_bind);
                        tv_sina_icon.setImageResource(R.drawable.sina_set_gray);
                        tv_sina_bind.setText("绑定");
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                super.onSuccess(statusCode, content);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                if (null != ProgressDialog && ProgressDialog.isShowing()) {
                    ProgressDialog.dismiss();
                }
                Toast.makeText(getApplicationContext(), "解绑失败", Toast.LENGTH_SHORT).show();
                super.onFailure(error, content);
            }
        });
    }

    private void deleteQQBind() {
        final ProgressHUD ProgressDialog = ProgressHUD.show(this, "正在加载...", true, true, null);
        AddClient.get(Address.UNBINDQQ, null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                try {
                    if (null != ProgressDialog && ProgressDialog.isShowing()) {
                        ProgressDialog.dismiss();
                    }
                    BaseEntity parse = JSON.parseObject(content, BaseEntity.class);
                    if (parse.getResult().equals("0")) {
                        loginByQQ = false;
                        iv_qq_bind.setImageResource(R.drawable.s_bind);
                        tv_qq_bind.setText("绑定");
                        tv_qq_icon.setImageResource(R.drawable.qqicon_set_gray);
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                super.onSuccess(statusCode, content);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                if (null != ProgressDialog && ProgressDialog.isShowing()) {
                    ProgressDialog.dismiss();
                }
                Toast.makeText(getApplicationContext(), "解绑失败", Toast.LENGTH_SHORT).show();
                super.onFailure(error, content);
            }
        });
    }

    private void deleteWeiXinBind() {
        final ProgressHUD ProgressDialog = ProgressHUD.show(this, "正在加载...", true, true, null);
        AddClient.get(Address.UNBINDWeiXin, null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                try {
                    if (null != ProgressDialog && ProgressDialog.isShowing()) {
                        ProgressDialog.dismiss();
                    }
                    BaseEntity parse = JSON.parseObject(content, BaseEntity.class);
                    if (parse.getResult().equals("0")) {
                        loginByWeiXin = false;
                        iv_weixin_bind.setImageResource(R.drawable.s_bind);
                        tv_weixin_bind.setText("绑定");
                        tv_weixin_icon.setImageResource(R.drawable.weixinicon_set_gray);
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        Toast.makeText(getApplicationContext(), parse.getMsg(), Toast.LENGTH_SHORT)
                                .show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                super.onSuccess(statusCode, content);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                if (null != ProgressDialog && ProgressDialog.isShowing()) {
                    ProgressDialog.dismiss();
                }
                Toast.makeText(getApplicationContext(), "解绑失败", Toast.LENGTH_SHORT).show();
                super.onFailure(error, content);
            }
        });
    }

    private ClearTask clearTask;

    private class ClearTask extends AsyncTask<String, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(String... params) {
            File cache = SettingActivity.this.getCacheDir();
            File[] child = cache.listFiles();
            for (int i = 0; i < child.length; i++) {
                try {
                    deleteFile(child[i]);
                } catch (Exception e) {
                }
            }
            cache.delete();
            return true;
        }

        private void deleteFile(File file) {
            if (file.exists()) {
                if (file.isDirectory()) {
                    File[] child = file.listFiles();
                    for (int i = 0; i < child.length; i++) {
                        deleteFile(child[i]);
                    }
                }
                file.delete();
            }
        }

        @Override
        protected void onPostExecute(Boolean result) {
            setting_huancun.setText("0KB");
            Toast.makeText(getApplicationContext(), "缓存清除成功", Toast.LENGTH_SHORT).show();
        }

    }

    private CharSequence getCacheSize() {
        File cacheDir = this.getCacheDir();
        long size = getSize(cacheDir);
        return Formatter.formatFileSize(this, size);
    }

    public long getSize(File file) {
        // 判断文件是否存在
        if (file.exists()) {
            // 如果是目录则递归计算其内容的总大小，如果是文件则直接返回其大小
            if (!file.isFile()) {
                // 获取文件大小
                File[] fl = file.listFiles();
                long ss = 0;
                for (File f : fl)
                    ss += getSize(f);
                return ss;
            } else {
                long ss = file.length();
                return ss;
            }
        } else {
            Toast.makeText(getApplicationContext(), "缓存文件为空", Toast.LENGTH_SHORT).show();
        }
        return 0;
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case 1: {
                ProgressDialog dialog = new ProgressDialog(this);
                dialog.setMessage("正在清楚缓存...");
                dialog.setIndeterminate(true);
                dialog.setCancelable(true);
                return dialog;
            }
        }
        return null;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if (mSsoHandler != null) {
        // mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
        // }
        if (LoginManager.mSsoHandler != null) {
            LoginManager.mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
        }
    }

    private static String getVersionCode(Activity context) {
        try {
            return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return "1";
    }

    private void checkUpdate() {
        final ProgressHUD progressHUD =
                ProgressHUD.show(SettingActivity.this, "正在检测中...", false, false, null);
        HappyPetApplication.get().getMoccaApi()
                .checkUpdate(getVersionCode(SettingActivity.this), new IRequest<UpdateInfo>() {
                    @Override
                    public void request(final UpdateInfo t) {
                        if (progressHUD != null) {
                            progressHUD.dismiss();
                        }
                        if (t == null) {
                            return;
                        }
                        if (t.needup.equals("1")) {
                            String force = t.force; // 判断是否强制更新
                            boolean flag_force = true;
                            if (force.equals("1")) {
                                flag_force = false;
                            } else {
                                flag_force = true;
                            }
                            if (null != t) {
                                switch (String.valueOf(getVersionCode(SettingActivity.this))
                                        .compareTo(t.version)) {
                                    case 0: // 版本一致,不更新

                                        break;
                                    case 1: // 当前版本更大,不更新

                                        break;
                                    default: // 低版本，更新
                                        // 加入红点提示
                                        SharePrefUtil.saveBoolean(getBaseContext(), "updatenew",
                                                true);
                                        if (flag_force) {
                                            new AlertDialog.Builder(SettingActivity.this)
                                                    .setTitle("版本升级")
                                                    .setMessage(t.content)
                                                    .setNegativeButton("立即更新",
                                                            new DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void onClick(
                                                                        DialogInterface dialog,
                                                                        int which) {
                                                                    CommonUtil.startWebView(
                                                                            SettingActivity.this,
                                                                            t.url);
                                                                }
                                                            })
                                                    .setPositiveButton("忽略本次",
                                                            new DialogInterface.OnClickListener() {

                                                                @Override
                                                                public void onClick(
                                                                        DialogInterface dialog,
                                                                        int which) {

                                                                }
                                                            }).create().show();
                                        } else {
                                            Builder alertDialog =
                                                    new AlertDialog.Builder(SettingActivity.this);
                                            alertDialog
                                                    .setTitle("版本升级")
                                                    .setMessage(t.content)
                                                    .setCancelable(false)
                                                    .setNegativeButton("立即更新",
                                                            new DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void onClick(
                                                                        DialogInterface dialog,
                                                                        int which) {
                                                                    CommonUtil.startWebView(
                                                                            SettingActivity.this,
                                                                            t.url);
                                                                    System.exit(0);
                                                                }
                                                            }).create().show();
                                            alertDialog
                                                    .setOnKeyListener(new DialogInterface.OnKeyListener() {
                                                        @Override
                                                        public boolean onKey(
                                                                DialogInterface dialog,
                                                                int keyCode, KeyEvent event) {
                                                            if (keyCode == KeyEvent.KEYCODE_BACK) {
                                                                return true;
                                                            } else {
                                                                return false; // 默认返回 false
                                                            }
                                                        }
                                                    });
                                        }
                                        break;
                                }
                            }
                        } else {
                            // 去掉红点提示
                            SharePrefUtil.saveBoolean(getBaseContext(), "updatenew", false);
                            Toast.makeText(SettingActivity.this, "当前版本为最新版本", Toast.LENGTH_SHORT)
                                    .show();
                        }

                    }
                });

    }

    class LoginSuccessReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            initWeiboBindStatus();
        }

    }
}
